<%@ page language="java" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>	
<%@ include file="/pub/headmeta.jsp" %>
</head>
<body class="edit-bgr-color">
	<div class="right-head"><span class="right-head-font">新增用户</span></div>
	<div align="center" style="width: 98%">	
		<form id="addForm" method="post" enctype="multipart/form-data">			
			<table cellpadding="5" style="width: 600px; font-size: 12px;">
				<tr>
					<td width="35%" align="right">帐号：</td>
					<td width="65%" align="left"><input type="text" name="account" id="account" style="width: 60%"/>&nbsp;&nbsp;<font color='red'>*</font>&nbsp;&nbsp;<a href="javascript:checkNoAccount();">检测</a>&nbsp;<span id='checkok' style="display: none;"><font color='green'>可用</font></span><span id='checkno' style="display: none;"><font color='red'>已注册</font></span></td>					
				</tr>
				<tr>
					<td align="right">初始密码：</td>
					<td align="left"><input type="password" name="pwd" id="pwd" style="width: 60%"/>&nbsp;&nbsp;<font color='red'>*</font></td>					
				</tr>
				<tr>
					<td align="right">角色：</td>
					<td align="left"><select name="roleId" id="roleId" style="width: 60%"></select></td>					
				</tr>
				<tr>
					<td align="right">昵称：</td>
					<td align="left"><input type="text" name="name" id="name" style="width: 60%"/></td>					
				</tr>
				<tr>
					<td align="right">性别：</td>
					<td align="left"><input type="radio" name="sex" value="1" checked="checked"/>男&nbsp;&nbsp;&nbsp;&nbsp;<input type="radio" name="sex" value="2"/>女</td>					
				</tr>
				<tr>
					<td align="right">生日：</td>
					<td align="left"><input type="text" name="birthday" id="birthday"   class="Wdate" onClick="WdatePicker()"/></td>					
				</tr>
				<tr>
					<td align="right">手机号码：</td>
					<td align="left"><input type="text" name="phone" id="phone" style="width: 60%"/></td>					
				</tr>
				<tr>
					<td align="right">电子邮件：</td>
					<td align="left"><input type="text" name="email" id="email" style="width: 60%"/></td>					
				</tr>
				<tr>
					<td align="right">身份证号：</td>
					<td><input type="text" name="idcard" id="idcard" style="width: 60%"/></td>					
				</tr>
			</table>
			<div class="edit-line"></div>
			<input  type="button" class="button-1" value="新增" onclick="doAdd();"/>
			<input  type="button" class="button-1" value="重置" onclick="resetEx(this.form);"/>						
			<input  type="button" class="button-1" value="返回" onclick="back();"/>
		</form>
	</div>
</body>
</html>
<script type="text/javascript">
<!--
//自动调用初始化
$(document).ready(function(){	
	//获取角色
	var url="${ctx}/role!getList.action?page=1&pageSize=100";
	$.ajax({type : "post", url : url, data : '', async : false, success : function callback(txt){   
		var json = $.parseJSON(txt);			
		if (json.code==0) {	
			var roles=json.info;					
			for(var n in roles){
				$("#roleId").append("<option value='"+roles[n].roleId+"'>"+roles[n].name+"</option>"); 
			}
		}else{
			alert('查询失败！');
		}
	}});
});

//新增
function doAdd() {
	if ($("#account").val()== ""){
		alert('帐号不能为空！');
		return;
	}
	if ($("#pwd").val()== ""||$("#pwd").val().length<6){
		alert('初始密码不能为空,且至少6位！');
		return;
	}
	//检测名字
	if(checkNoAccount()){
		var form=$("#addForm");
		form.attr("action","${ctx}/user!add.action"); 
		form.submit();
	}	
}

//检测帐号
function checkNoAccount(){
	var flag=false;
	if(''!=$("#account").val()){
		var url="${ctx}/user!checkNoAccount.action";
		$.ajax({type : "post", url : url, data : 'account='+$("#account").val(), async : false, success : function callback(txt){   
			var json = $.parseJSON(txt);			
			if (json.code==0) {	
				 $('#checkok').attr('style','display:;');	
				 $('#checkno').attr('style','display:none;');
				 flag=true;
			}else{
				 $('#checkok').attr('style','display:none;');	
				 $('#checkno').attr('style','display:;');  			
			}
		}});
	}
	return flag;
}

//返回
function back(){
	location.href="${ctx}/user!viewList.action";
}
//-->
</script>
